// var i;
// var $bundleConfig = require("./BundleConfig");
// var $aDManager = require("./ADManager");
// var $eventManager = require("./EventManager");
// var $resLoader = require("./ResLoader");
// var $uIManager = require("./UIManager");
// var $timeUtils = require("./TimeUtils");
// var $module_Shop_UIBindings = require("./Module_Shop_UIBindings");
// var $evenType = require("./EvenType");
// var $excel = require("./Excel");
// var $hallManager = require("./HallManager");
// var $item_Shop_BoxItem = require("./Item_Shop_BoxItem");
// var $item_Shop_GoldItem = require("./Item_Shop_GoldItem");
// var $item_Shop_TodayItem = require("./Item_Shop_TodayItem");
// var $uIConfig_Home = require("./UIConfig_Home");
// var $baseModule = require("./BaseModule");
// var E = cc._decorator;
// var x = E.ccclass;
// var C = E.property;
// var B = E.inspector;
// var k = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         t.timeStr = "";
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.onLoad = function () {
//         $eventManager.EventMgr.addEventListener($evenType.EVENT_TYPE.HallResetShopBox, this.ResetBoxLevelAndExp, this);
//         $eventManager.EventMgr.addEventListener($evenType.EVENT_TYPE.HallScrollShop, this.EventScroll, this);
//     };
//     t.prototype.onDestroy = function () {
//         e.prototype.onDestroy.call(this);
//         $eventManager.EventMgr.rmEventListener($evenType.EVENT_TYPE.HallResetShopBox, this.ResetBoxLevelAndExp, this);
//         $eventManager.EventMgr.rmEventListener($evenType.EVENT_TYPE.HallScrollShop, this.EventScroll, this);
//     };
//     t.prototype.show = function (e) {
//         this.auto_ui.addClickListener(this._clickListener, this);
//         this.StartSet(e);
//     };
//     t.prototype.EventScroll = function (e) {
//         if (e) {
//             e.isUp
//                 ? this.node.getChildByName("ScrollView_Main").getComponent(cc.ScrollView).scrollToTop(0.2)
//                 : e.isBottom &&
//                   this.node.getChildByName("ScrollView_Main").getComponent(cc.ScrollView).scrollToBottom(0.2);
//         }
//     };
//     t.prototype.hide = function () {};
//     t.prototype.StartSet = function (e) {
//         var t = this;
//         if (void 0 === e) {
//             e = null;
//         }
//         var o = $excel.Excel.shopControl(1);
//         var n = this.auto_ui;
//         var i = $hallManager.HallMgr.CheckNextResetTime();
//         this.ShowTimeLabel(i);
//         this.auto_ui.btn_ResetTodayBtn.interactable =
//             o.lastResetCount - $hallManager.HallMgr.shopData.todayResetCount > 0;
//         var a = i;
//         n.txt_todayResetTimeLabel.node.stopAllActions();
//         n.txt_todayResetTimeLabel.node.runAction(
//             cc.repeat(
//                 cc.sequence(
//                     cc.delayTime(1),
//                     cc.callFunc(function () {
//                         i--;
//                         t.ShowTimeLabel(i);
//                         if (i < 0) {
//                             t.StartSet();
//                         }
//                     })
//                 ),
//                 a
//             )
//         );
//         n.txt_todayLastCountLabel.string = "" + (o.lastResetCount - $hallManager.HallMgr.shopData.todayResetCount);
//         this.ResetBoxLevelAndExp();
//         this.ShowTodayItem().then(function () {
//             t.ShowBoxItem().then(function () {
//                 t.ShowGoldItem().then(function () {
//                     if (e) {
//                         t.scheduleOnce(function () {
//                             t.EventScroll(e);
//                         });
//                     }
//                 });
//             });
//         });
//     };
//     t.prototype.ShowTodayItem = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             var e;
//             var t;
//             var o;
//             return __generator(this, function (n) {
//                 switch (n.label) {
//                     case 0:
//                         if (0 != (e = this.auto_ui.node_todayFather).childrenCount) {
//                             return [3, 2];
//                         } else {
//                             return [
//                                 4,
//                                 $resLoader.default.loadRes(
//                                     $bundleConfig.BundleNames.Home,
//                                     "item/item_shop_todayItem",
//                                     cc.Prefab
//                                 )
//                             ];
//                         }
//                     case 1:
//                         for (t = n.sent(), o = 0; o < 6; o++) {
//                             e.addChild(cc.instantiate(t));
//                         }
//                         n.label = 2;
//                     case 2:
//                         for (o = 0; o < e.children.length; o++) {
//                             e.children[o].getComponent($item_Shop_TodayItem.default).StartSet(o);
//                         }
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.ShowBoxItem = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             var e;
//             var t;
//             var o;
//             return __generator(this, function (n) {
//                 switch (n.label) {
//                     case 0:
//                         if (0 != (e = this.auto_ui.node_boxFather).childrenCount) {
//                             return [3, 2];
//                         } else {
//                             return [
//                                 4,
//                                 $resLoader.default.loadRes(
//                                     $bundleConfig.BundleNames.Home,
//                                     "item/item_shop_boxItem",
//                                     cc.Prefab
//                                 )
//                             ];
//                         }
//                     case 1:
//                         for (t = n.sent(), o = 0; o < 2; o++) {
//                             e.addChild(cc.instantiate(t));
//                         }
//                         n.label = 2;
//                     case 2:
//                         for (o = 0; o < e.children.length; o++) {
//                             e.children[o]
//                                 .getComponent($item_Shop_BoxItem.default)
//                                 .StartSet(o, this.auto_ui.txt_todayResetTimeLabel);
//                         }
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.ShowGoldItem = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             var e;
//             var t;
//             var o;
//             return __generator(this, function (n) {
//                 switch (n.label) {
//                     case 0:
//                         if (0 != (e = this.auto_ui.node_goldFather).childrenCount) {
//                             return [3, 2];
//                         } else {
//                             return [
//                                 4,
//                                 $resLoader.default.loadRes(
//                                     $bundleConfig.BundleNames.Home,
//                                     "item/item_shop_goldItem",
//                                     cc.Prefab
//                                 )
//                             ];
//                         }
//                     case 1:
//                         for (t = n.sent(), o = 0; o < 3; o++) {
//                             e.addChild(cc.instantiate(t));
//                         }
//                         n.label = 2;
//                     case 2:
//                         for (o = 0; o < e.children.length; o++) {
//                             e.children[o].getComponent($item_Shop_GoldItem.default).StartSet(o);
//                         }
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.ShowTimeLabel = function (e) {
//         this.timeStr = $timeUtils.default.secondsToHMS(e);
//         this.auto_ui.txt_todayResetTimeLabel.string = this.timeStr;
//     };
//     t.prototype._clickListener = function (e) {
//         switch (e) {
//             case this.auto_ui.btn_ResetTodayBtn:
//                 this.ResetTodayShop();
//                 break;
//             case this.auto_ui.btn_boxExpInfoBtn:
//                 $uIManager.default.open($bundleConfig.BundleNames.Home, $uIConfig_Home.UIView_Home.UI_BoxLevelInfo);
//         }
//     };
//     t.prototype.ResetTodayShop = function () {
//         var e = this;
//         var t = $excel.Excel.shopControl(1);
//         if (t.lastResetCount - $hallManager.HallMgr.shopData.todayResetCount != 0) {
//             $aDManager.ADMgr.showRewardedVideo("商城视频刷新每日商店", function () {
//                 $hallManager.HallMgr.shopData.todayResetCount++;
//                 $hallManager.HallMgr.ResetTodayShop();
//                 e.ShowTodayItem();
//                 var o = t.lastResetCount - $hallManager.HallMgr.shopData.todayResetCount;
//                 e.auto_ui.txt_todayLastCountLabel.string = "" + o;
//                 if (o <= 0) {
//                     e.auto_ui.btn_ResetTodayBtn.interactable = !1;
//                 }
//             });
//         } else {
//             this.auto_ui.btn_ResetTodayBtn.interactable = !1;
//         }
//     };
//     t.prototype.ResetBoxLevelAndExp = function () {
//         var e = $excel.Excel.shopBoxLevel($hallManager.HallMgr.shopData.boxLevel + 1);
//         if ($hallManager.HallMgr.shopData.boxExp >= e.exp && e.exp > 0) {
//             $hallManager.HallMgr.shopData.boxLevel++;
//             $hallManager.HallMgr.shopData.boxExp -= e.exp;
//             e = $excel.Excel.shopBoxLevel($hallManager.HallMgr.shopData.boxLevel + 1);
//         }
//         this.auto_ui.txt_boxLevelLabel.string = "LV." + ($hallManager.HallMgr.shopData.boxLevel + 1);
//         if (e && e.exp) {
//             this.auto_ui.txt_boxExpLabel.string = $hallManager.HallMgr.shopData.boxExp + "/" + e.exp;
//             this.auto_ui.progress_boxExpBar.progress = $hallManager.HallMgr.shopData.boxExp / e.exp;
//         } else {
//             this.auto_ui.txt_boxExpLabel.string = "MAX";
//             this.auto_ui.progress_boxExpBar.progress = 1;
//         }
//     };
//     __decorate([C($module_Shop_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     return __decorate([x], t);
// })($baseModule.default);
// exports.default = k;


// import { BundleNames } from "./BundleConfig";
// import { ADMgr } from "./ADManager";
// import { EventMgrInstance } from "./EventManager";
// import ResLoader from "./ResLoader";
// import UIManager from "./UIManager";
// import TimeUtils from "./TimeUtils";
// import Module_Shop_UIBindings from "./Module_Shop_UIBindings";
// import { EVENT_TYPE } from "./EvenType";
// import { Excel } from "./Excel";
// import { HallMgrInstance } from "./HallManager";
// import Item_Shop_BoxItem from "./Item_Shop_BoxItem";
// import Item_Shop_GoldItem from "./Item_Shop_GoldItem";
// import Item_Shop_TodayItem from "./Item_Shop_TodayItem";

// import BaseModule from "./BaseModule";
// import { UIView_Home } from "./UIConfig_Home";

// const { ccclass, property, inspector } = cc._decorator;

// /**
//  * 建议类名: ShopModule
//  */
// @ccclass
// class Module_Shop extends BaseModule {
//     @property(Module_Shop_UIBindings)
//     auto_ui: any = null;

//     private timeStr: string = "";

//     /**
//      * 建议方法名: handleOnLoad
//      */
//     onLoad(): void {
//         EventMgrInstance.addEventListener(EVENT_TYPE.HallResetShopBox, this.ResetBoxLevelAndExp, this);
//         EventMgrInstance.addEventListener(EVENT_TYPE.HallScrollShop, this.EventScroll, this);
//     }

//     /**
//      * 建议方法名: handleOnDestroy
//      */
//     onDestroy(): void {
//         super.onDestroy();
//         EventMgrInstance.rmEventListener(EVENT_TYPE.HallResetShopBox, this.ResetBoxLevelAndExp, this);
//         EventMgrInstance.rmEventListener(EVENT_TYPE.HallScrollShop, this.EventScroll, this);
//     }

//     /**
//      * 建议方法名: display
//      * @param e - 参数e的意义不明确，请提供更多信息
//      */
//     show(e: any): void {
//         this.auto_ui.addClickListener(this._clickListener, this);
//         this.StartSet(e);
//     }

//     /**
//      * 建议方法名: handleEventScroll
//      * @param e - 参数e的意义不明确，请提供更多信息
//      */
//     EventScroll(e: any): void {
//         if (e) {
//             e.isUp
//                 ? this.node.getChildByName("ScrollView_Main").getComponent(cc.ScrollView).scrollToTop(0.2)
//                 : e.isBottom &&
//                 this.node.getChildByName("ScrollView_Main").getComponent(cc.ScrollView).scrollToBottom(0.2);
//         }
//     }

//     /**
//      * 建议方法名: hideModule
//      */
//     hide(): void { }

//     /**
//      * 建议方法名: initializeSettings
//      * @param e - 参数e的意义不明确，请提供更多信息
//      */
//     StartSet(e?: any): void {
//         if (e === undefined) {
//             e = null;
//         }
//         const shopControl = Excel.shopControl(1);
//         const ui = this.auto_ui;
//         let resetTime = HallMgrInstance.CheckNextResetTime();
//         this.ShowTimeLabel(resetTime);
//         this.auto_ui.btn_ResetTodayBtn.interactable =
//             shopControl.lastResetCount - HallMgrInstance.shopData.todayResetCount > 0;
//         const totalTime = resetTime;
//         ui.txt_todayResetTimeLabel.node.stopAllActions();
//         ui.txt_todayResetTimeLabel.node.runAction(
//             cc.repeat(
//                 cc.sequence(
//                     cc.delayTime(1),
//                     cc.callFunc(() => {
//                         resetTime--;
//                         this.ShowTimeLabel(resetTime);
//                         if (resetTime < 0) {
//                             this.StartSet();
//                         }
//                     })
//                 ),
//                 totalTime
//             )
//         );
//         ui.txt_todayLastCountLabel.string = `${shopControl.lastResetCount - HallMgrInstance.shopData.todayResetCount}`;
//         this.ResetBoxLevelAndExp();
//         this.ShowTodayItem().then(() => {
//             this.ShowBoxItem().then(() => {
//                 this.ShowGoldItem().then(() => {
//                     if (e) {
//                         this.scheduleOnce(() => {
//                             this.EventScroll(e);
//                         });
//                     }
//                 });
//             });
//         });
//     }

//     /**
//      * 建议方法名: displayTodayItems
//      */
//     async ShowTodayItem(): Promise<void> {
//         const todayFather = this.auto_ui.node_todayFather;
//         if (todayFather.childrenCount === 0) {
//             const prefab = await ResLoader.loadRes(
//                 BundleNames.Home,
//                 "item/item_shop_todayItem",
//                 cc.Prefab
//             );
//             for (let i = 0; i < 6; i++) {
//                 todayFather.addChild(cc.instantiate(prefab));
//             }
//         }
//         for (let i = 0; i < todayFather.children.length; i++) {
//             todayFather.children[i].getComponent(Item_Shop_TodayItem).StartSet(i);
//         }
//     }

//     /**
//      * 建议方法名: displayBoxItems
//      */
//     async ShowBoxItem(): Promise<void> {
//         const boxFather = this.auto_ui.node_boxFather;
//         if (boxFather.childrenCount === 0) {
//             const prefab = await ResLoader.loadRes(
//                 BundleNames.Home,
//                 "item/item_shop_boxItem",
//                 cc.Prefab
//             );
//             for (let i = 0; i < 2; i++) {
//                 boxFather.addChild(cc.instantiate(prefab));
//             }
//         }
//         for (let i = 0; i < boxFather.children.length; i++) {
//             boxFather.children[i]
//                 .getComponent(Item_Shop_BoxItem)
//                 .StartSet(i, this.auto_ui.txt_todayResetTimeLabel);
//         }
//     }

//     /**
//      * 建议方法名: displayGoldItems
//      */
//     async ShowGoldItem(): Promise<void> {
//         const goldFather = this.auto_ui.node_goldFather;
//         if (goldFather.childrenCount === 0) {
//             const prefab = await ResLoader.loadRes(
//                 BundleNames.Home,
//                 "item/item_shop_goldItem",
//                 cc.Prefab
//             );
//             for (let i = 0; i < 3; i++) {
//                 goldFather.addChild(cc.instantiate(prefab));
//             }
//         }
//         for (let i = 0; i < goldFather.children.length; i++) {
//             goldFather.children[i].getComponent(Item_Shop_GoldItem).StartSet(i);
//         }
//     }

//     /**
//      * 建议方法名: updateTimeLabel
//      * @param seconds - 剩余时间的秒数
//      */
//     ShowTimeLabel(seconds: number): void {
//         this.timeStr = TimeUtils.secondsToHMS(seconds);
//         this.auto_ui.txt_todayResetTimeLabel.string = this.timeStr;
//     }

//     /**
//      * 建议方法名: handleClickListener
//      * @param event - 点击事件
//      */
//     _clickListener(event: cc.Button): void {
//         switch (event) {
//             case this.auto_ui.btn_ResetTodayBtn:
//                 this.ResetTodayShop();
//                 break;
//             case this.auto_ui.btn_boxExpInfoBtn:
//                 UIManager.open(BundleNames.Home, UIView_Home.UI_BoxLevelInfo);
//         }
//     }

//     /**
//      * 建议方法名: resetTodayShopItems
//      */
//     ResetTodayShop(): void {
//         const shopControl = Excel.shopControl(1);
//         if (shopControl.lastResetCount - HallMgrInstance.shopData.todayResetCount !== 0) {
//             ADMgr.showRewardedVideo("商城视频刷新每日商店", () => {
//                 HallMgrInstance.shopData.todayResetCount++;
//                 HallMgrInstance.ResetTodayShop();
//                 this.ShowTodayItem();
//                 const remainingCount = shopControl.lastResetCount - HallMgrInstance.shopData.todayResetCount;
//                 this.auto_ui.txt_todayLastCountLabel.string = `${remainingCount}`;
//                 if (remainingCount <= 0) {
//                     this.auto_ui.btn_ResetTodayBtn.interactable = false;
//                 }
//             });
//         } else {
//             this.auto_ui.btn_ResetTodayBtn.interactable = false;
//         }
//     }

//     /**
//      * 建议方法名: resetBoxLevelAndExperience
//      */
//     ResetBoxLevelAndExp(): void {
//         let boxLevelData = Excel.shopBoxLevel(HallMgrInstance.shopData.boxLevel + 1);
//         if (HallMgrInstance.shopData.boxExp >= boxLevelData.exp && boxLevelData.exp > 0) {
//             HallMgrInstance.shopData.boxLevel++;
//             HallMgrInstance.shopData.boxExp -= boxLevelData.exp;
//             boxLevelData = Excel.shopBoxLevel(HallMgrInstance.shopData.boxLevel + 1);
//         }
//         this.auto_ui.txt_boxLevelLabel.string = `LV.${HallMgrInstance.shopData.boxLevel + 1}`;
//         if (boxLevelData && boxLevelData.exp) {
//             this.auto_ui.txt_boxExpLabel.string = `${HallMgrInstance.shopData.boxExp}/${boxLevelData.exp}`;
//             this.auto_ui.progress_boxExpBar.progress = HallMgrInstance.shopData.boxExp / boxLevelData.exp;
//         } else {
//             this.auto_ui.txt_boxExpLabel.string = "MAX";
//             this.auto_ui.progress_boxExpBar.progress = 1;
//         }
//     }
// }

// export default Module_Shop;

import { BundleNames } from "./BundleConfig";
import { ADMgr } from "./ADManager";
import { EventMgrInstance } from "./EventManager";
import ResLoader from "./ResLoader";
import UIManager from "./UIManager";
import TimeUtils from "./TimeUtils";
import ModuleShopUIBindings from "./Module_Shop_UIBindings";
import { EVENT_TYPE } from "./EvenType";
import { Excel } from "./Excel";
import { HallMgr } from "./HallManager";
import ItemShopBoxItem from "./Item_Shop_BoxItem";
import ShopGoldItem from "./Item_Shop_GoldItem";
import ShopTodayItem from "./Item_Shop_TodayItem";

import BaseModule from "./BaseModule";
import { UIView_Home } from "./UIConfig_Home";

const { ccclass, property, inspector } = cc._decorator;

/**
 * 建议类名：ShopModule
 * 购物模块
 */
@ccclass
class ModuleShop extends BaseModule {
    @property(ModuleShopUIBindings)
    auto_ui: ModuleShopUIBindings = null;

    private formattedTimeString: string = "";

    /**
     * 建议方法名：handleOnLoad
     * 加载事件处理
     */
    onLoad(): void {
        EventMgrInstance.addListener(EVENT_TYPE.HallResetShopBox, this.resetBoxLevelAndExp, this);
        EventMgrInstance.addListener(EVENT_TYPE.HallScrollShop, this.handleEventScroll, this);
    }

    /**
     * 建议方法名：handleOnDestroy
     * 销毁事件处理
     */
    onDestroy(): void {
        super.onDestroy();
        EventMgrInstance.removeListener(EVENT_TYPE.HallResetShopBox, this.resetBoxLevelAndExp, this);
        EventMgrInstance.removeListener(EVENT_TYPE.HallScrollShop, this.handleEventScroll, this);
    }

    /**
     * 建议方法名：display
     * 显示商城内容
     * @param showParams 显示参数
     */
    show(showParams: any): void {
        this.auto_ui.addClickListener(this._clickListener, this);
        this.initializeSettings(showParams);
    }

    /**
     * 建议方法名：handleEventScroll
     * 处理滚动事件
     * @param scrollEvent 滚动事件
     */
    handleEventScroll(scrollEvent: any): void {
        if (scrollEvent) {
            scrollEvent.isUp
                ? this.node.getChildByName("ScrollView_Main").getComponent(cc.ScrollView).scrollToTop(0.2)
                : scrollEvent.isBottom &&
                  this.node.getChildByName("ScrollView_Main").getComponent(cc.ScrollView).scrollToBottom(0.2);
        }
    }

    /**
     * 建议方法名：hideModule
     * 隐藏模块
     */
    hide(): void { }

    /**
     * 建议方法名：initializeSettings
     * 初始化设置
     * @param initParams 初始化参数
     */
    initializeSettings(initParams: any = null): void {
        const shopControl = Excel.shopControl(1);
        const uiBindings = this.auto_ui;
        let resetTime = HallMgr.checkNextResetTime();
        this.showTimeLabel(resetTime);
        uiBindings.btn_ResetTodayBtn.interactable = shopControl.lastResetCount - HallMgr.shopData.todayResetCount > 0;
        uiBindings.txt_todayResetTimeLabel.node.stopAllActions();
        uiBindings.txt_todayResetTimeLabel.node.runAction(
            cc.repeat(
                cc.sequence(
                    cc.delayTime(1),
                    cc.callFunc(() => {
                        resetTime--;
                        this.showTimeLabel(resetTime);
                        if (resetTime < 0) {
                            this.initializeSettings();
                        }
                    })
                ),
                resetTime
            )
        );
        uiBindings.txt_todayLastCountLabel.string = `${shopControl.lastResetCount - HallMgr.shopData.todayResetCount}`;
        this.resetBoxLevelAndExp();
        this.showTodayItem().then(() => {
            this.showBoxItem().then(() => {
                this.showGoldItem().then(() => {
                    if (initParams) {
                        this.scheduleOnce(() => {
                            this.handleEventScroll(initParams);
                        });
                    }
                });
            });
        });
    }

    /**
     * 建议方法名：displayTodayItems
     * 显示今日物品
     */
    async showTodayItem(): Promise<void> {
        const todayItemsParent = this.auto_ui.node_todayFather;
        if (todayItemsParent.childrenCount === 0) {
            const itemPrefab = await ResLoader.loadRes(BundleNames.Home, "item/item_shop_todayItem", cc.Prefab);
            for (let i = 0; i < 6; i++) {
                todayItemsParent.addChild(cc.instantiate(itemPrefab));
            }
        }
        todayItemsParent.children.forEach((childNode, index) => {
            childNode.getComponent(ShopTodayItem).initializeSettings(index);
        });
    }

    /**
     * 建议方法名：displayBoxItems
     * 显示箱子物品
     */
    async showBoxItem(): Promise<void> {
        const boxItemsParent = this.auto_ui.node_boxFather;
        if (boxItemsParent.childrenCount === 0) {
            const itemPrefab = await ResLoader.loadRes(BundleNames.Home, "item/item_shop_boxItem", cc.Prefab);
            for (let i = 0; i < 2; i++) {
                boxItemsParent.addChild(cc.instantiate(itemPrefab));
            }
        }
        boxItemsParent.children.forEach((childNode, index) => {
            childNode.getComponent(ItemShopBoxItem).initialize(index, this.auto_ui.txt_todayResetTimeLabel);
        });
    }

    /**
     * 建议方法名：displayGoldItems
     * 显示金币物品
     */
    async showGoldItem(): Promise<void> {
        const goldItemsParent = this.auto_ui.node_goldFather;
        if (goldItemsParent.childrenCount === 0) {
            const itemPrefab = await ResLoader.loadRes(BundleNames.Home, "item/item_shop_goldItem", cc.Prefab);
            for (let i = 0; i < 3; i++) {
                goldItemsParent.addChild(cc.instantiate(itemPrefab));
            }
        }
        goldItemsParent.children.forEach((childNode, index) => {
            childNode.getComponent(ShopGoldItem).initializeSettings(index);
        });
    }

    /**
     * 建议方法名：updateTimeLabel
     * 更新时间标签
     * @param seconds 剩余时间的秒数
     */
    showTimeLabel(seconds: number): void {
        this.formattedTimeString = TimeUtils.convertSecondsToHMS(seconds);
        this.auto_ui.txt_todayResetTimeLabel.string = this.formattedTimeString;
    }

    /**
     * 建议方法名：handleClickListener
     * 点击事件处理
     * @param event 点击事件
     */
    _clickListener(event: cc.Button): void {
        switch (event) {
            case this.auto_ui.btn_ResetTodayBtn:
                this.resetTodayShop();
                break;
            case this.auto_ui.btn_boxExpInfoBtn:
                UIManager.open(BundleNames.Home, UIView_Home.UI_BoxLevelInfo);
                break;
        }
    }

    /**
     * 建议方法名：resetTodayShopItems
     * 重置今日商城物品
     */
    resetTodayShop(): void {
        const shopControlData = Excel.shopControl(1);
        if (shopControlData.lastResetCount - HallMgr.shopData.todayResetCount > 0) {
            ADMgr.showRewardedVideoAd("商城视频刷新每日商店", () => {
                HallMgr.shopData.todayResetCount++;
                HallMgr.ResetTodayShop();
                this.showTodayItem();
                const remainingCount = shopControlData.lastResetCount - HallMgr.shopData.todayResetCount;
                this.auto_ui.txt_todayLastCountLabel.string = `${remainingCount}`;
                this.auto_ui.btn_ResetTodayBtn.interactable = remainingCount > 0; 
            });
        } else {
            this.auto_ui.btn_ResetTodayBtn.interactable = false;
        }
    }

    /**
     * 建议方法名：resetBoxLevelAndExperience
     * 重置箱子等级和经验
     */
    resetBoxLevelAndExp(): void {
        let currentBoxLevelData = Excel.shopBoxLevel(HallMgr.shopData.boxLevel + 1);
        while (HallMgr.shopData.boxExp >= currentBoxLevelData.exp && currentBoxLevelData.exp > 0) {
            HallMgr.shopData.boxLevel++;
            HallMgr.shopData.boxExp -= currentBoxLevelData.exp;
            currentBoxLevelData = Excel.shopBoxLevel(HallMgr.shopData.boxLevel + 1);
        }
        this.auto_ui.txt_boxLevelLabel.string = `LV.${HallMgr.shopData.boxLevel + 1}`;
        if (currentBoxLevelData && currentBoxLevelData.exp) {
            this.auto_ui.txt_boxExpLabel.string = `${HallMgr.shopData.boxExp}/${currentBoxLevelData.exp}`;
            this.auto_ui.progress_boxExpBar.progress = HallMgr.shopData.boxExp / currentBoxLevelData.exp;
        } else {
            this.auto_ui.txt_boxExpLabel.string = "MAX";
            this.auto_ui.progress_boxExpBar.progress = 1;
        }
    }
}

export default ModuleShop;